﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

using CE.Database;
using CE.Global;
using CE.User;
using CE.Job;

public partial class user_application : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("login.aspx");
        }
        if (!IsPostBack)
        {
            JobDataBind();
        }
    }
    private void JobDataBind()
    {
        GetActiveJobs();


        dlJob.DataSource = (PagedDataSource)Cache["ActiveJobs"];
        dlJob.DataBind();


        //if (dlJob.Items.Count == 0)
        //    pnlNoRecords.Visible = true;
        //else
        //    pnlNoRecords.Visible = false;

    }
    private void GetActiveJobs()
    {
        Int64 _uid = Int64.Parse(Session[CE.Global.General.UserId].ToString());
        MyDatabase _db = new MyDatabase();
        DataSet _dsResult = new DataSet();
        string _spName = "[sprocApplicationSelectSingleItemByUserID]";
        SortedList _spara = new SortedList();
        _spara.Add("@RefUserID", _uid);
        _dsResult = _db.GetDataSet(_spName, _spara);

        PagedDataSource pageds = new PagedDataSource();
        pageds.DataSource = _dsResult.Tables[0].DefaultView;
        pageds.AllowPaging = true;
        pageds.PageSize = 10;

        int curpage = 0;

        if (Request.QueryString["page"] != null)
        {
            curpage = Convert.ToInt32(Request.QueryString["page"]);
        }
        else
        {
            curpage = 1;
        }

        pageds.CurrentPageIndex = curpage - 1;

        if (curpage == 1 && pageds.DataSourceCount > pageds.PageSize)
            lblCurrpage.Text = "Pages: 1";
        else if (pageds.DataSourceCount == 0)
            lblCurrpage.Text = "No data to display.";
        else if (curpage > 1 && pageds.DataSourceCount > pageds.PageSize)
            lblCurrpage.Text = "Pages: <a href='application.aspx?page=1#list-contet'>1</a>";
        for (int i = 2; i <= pageds.PageCount; i++)
        {
            if (i == curpage)
                lblCurrpage.Text = lblCurrpage.Text + " " + i.ToString();
            else
                lblCurrpage.Text = lblCurrpage.Text + " <a href='job-list.aspx?page=" + i.ToString() + "#list-contet'>" + i.ToString() + "</a>";
        }

        Cache["ActiveJobs"] = pageds;
    }
}

